// 类修饰
// 第一个参数target，指向类本身
const classTestable = (target) => {
	target.isTestable = true;
}
// function classTestable(target) {
// 	target.isTestable = true;
// }

@classTestable
class ClassDecoratorExam {}
let classDecoratorExam = new ClassDecoratorExam();
console.log(`ClassDecoratorExam.isTestable: ${ClassDecoratorExam.isTestable}, classDecoratorExam.isTestable: ${classDecoratorExam.isTestable}`); //true, undefined

// 方法修饰
// 3个参数：target（类的原型对象）、name（修饰的属性名）、descriptor（该属性的描述对象）。
const readOnly = (target, name, descriptor) => {
	console.log(`${name}'s method decorator.`);
	descriptor.writable = false;
    return descriptor; // 必须返回
}
function logMethod(id) {
    console.log('evaluated logMethod'+id);
    return (target, name, desctiptor) => console.log('excuted         logMethod '+id);
}
@classTestable
class MethodDecoratorExam {
	@readOnly
    @logMethod
    sum(a, b) {
        return a + b;
    }
}

let mde = new MethodDecoratorExam();
console.log(`>>> sum: ${mde.sum(20, 68)}`);